package conf

import (
	"kubernate-server/module"

	"github.com/fsnotify/fsnotify"
	"github.com/spf13/viper"
)

type MydbConfig struct {
	DB module.DBConfig
}

var MyConf = &MydbConfig{}

func InitConfig(configPath string) *MydbConfig {
	viper.SetConfigFile("conf/conf.yaml")
	viper.SetConfigType("yaml")
	viper.SetConfigFile(configPath)
	err := viper.ReadInConfig()
	if err != nil {
		panic(err)
	}
	err = viper.Unmarshal(&MyConf)
	if err != nil {
		panic(err)
	}
	viper.WatchConfig()
	viper.OnConfigChange(func(in fsnotify.Event) {
		err = viper.Unmarshal(&MyConf)
		if err != nil {
			panic(err)
		}
	})
	return MyConf

}
